package com.huawei.control.muserinfo;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huawei.bean.MUserInfoBean;
import com.huawei.bean.Phones;
import com.huawei.bean.userInfoBean;
import com.huawei.model.MUserInfoModel;
import com.huawei.model.UserInfoModel;
import com.huawei.utils.EasyFactory;
import com.huawei.utils.MyUtils;

@WebServlet("/MUserInfoAjaxSavingControl")
@MultipartConfig(maxFileSize=10485760) // 限制上传文件大小，以bit为单位
public class MUserInfoAjaxSavingControl extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 将request中的form表单中的数据转换到实体类中
		MUserInfoBean muserInfoB = MyUtils.convertRequest2BeanWithFileUpload(request, MUserInfoBean.class);
		System.out.println(muserInfoB.toString());
		// 调用Model层进行用户信息保存的业务逻辑处理
		int i = 1;
		i= EasyFactory.getNewInstance(MUserInfoModel.class).saveOrUpdateMUserInfo(muserInfoB);
		
		// 根据业务逻辑处理结果，进行结果页面的转发处理
		if(i >0) {
			// 新增成功
			// 返回响应内容
			response.getWriter().write("ok");
		}else {
			// 新增失败
			response.getWriter().write("ng");
		}
		
	}
}
